
import os, os.path
import re
import sys
import glob
import platform


def BuildLibSMALL(env):
    Small_Dir = '../../libs/smallkit-1.8.4'
    SMALL_SOURCES  = glob.glob(Small_Dir+'/*.c')
    SMALL_SOURCES += glob.glob(Small_Dir+'/*.cpp')
    print SMALL_SOURCES
    env_small = env.Clone();
    SMALL_SOURCES_Platform = []
    if env['OS'] in ("Darwin" ):
		print "Darwin Platform not Supported, Please fix."
		exit(1);
    if env['OS'] in ("Linux" ):
		# Remove a few entries that are not required.
		env_small.Append(CPPPATH=[Small_Dir+'linux']);
		SMALL_SOURCES_Platform += glob.glob(Small_Dir+'/linux/*.c')
		SMALL_SOURCES_Platform += glob.glob(Small_Dir+'/linux/*.cpp')
		SMALL_SOURCES.remove(Small_Dir+'/BFixed.c')
		#return;
    elif env['OS'] in ("Windows"):
		env_small.Append(CPPDEFINES = ['PAWN_CELL_SIZE=64'])
		# remove Duplicate Definition.
		SMALL_SOURCES.remove(Small_Dir+'\\BFixed.c')
		#env.Append(LIBS = ['m','dl'])			
    else:
		#TODO:  fix this on other platforms.
		return;
    print "Building libSMALL"
    #it might be better to add this define for compile... AMX_NODYNALOAD
    env_small.Append(CPPPATH=[Small_Dir+'linux',Small_Dir+'compiler'])
    env_small.Append(CPPDEFINES = ['NO_MAIN'])
    # build the Pawn environment.
    small_lib = env_small.StaticLibrary(
        target = 'out/libs/libSMALL',
        source = [SMALL_SOURCES,SMALL_SOURCES_Platform])

    return small_lib
